// 假设您有一个提供国家列表的API端点
const countriesApiUrl = 'https://your-api-endpoint.com/countries';

// 使用fetch API获取国家数据
fetch(countriesApiUrl)
	.then(response => {
		if (!response.ok) {
			throw new Error('Network response was not ok');
		}
		return response.json();
	})
	.then(data => {
		// 清空选择框
		const select = document.getElementById('countrySelect');
		select.innerHTML = '<option value="">请选择国家或地区</option>';

		// 将获取到的国家数据添加到选择框中
		data.forEach(country => {
			const option = document.createElement('option');
			option.value = country.code;
			option.textContent = country.name;
			select.appendChild(option);
		});
	})
	.catch(error => {
		console.error('There has been a problem with your fetch operation:', error);
		const select = document.getElementById('countrySelect');
		select.innerHTML = '<option value="">加载失败，请重试</option>';
	});

function togglePasswordVisibility() {
	var passwordInput = document.getElementById('password');
	var toggleButton = document.getElementById('toggleButton');
	if (passwordInput.type === 'password') {
		passwordInput.type = 'text';
		toggleButton.textContent = '隐藏密码';
	} else {
		passwordInput.type = 'password';
		toggleButton.textContent = '显示密码';
	}
}

function validateInput(event) {
	// 创建正则表达式，允许字母、数字和下划线
	var regex = /[^a-zA-Z0-9_]/g;

	// 如果输入不符合正则表达式，阻止它
	if (regex.test(event.key)) {
		event.preventDefault();
	}
}

function validatePassword(event) {
	var passwordInput = event.target;
	var password = passwordInput.value;

	// 创建正则表达式，允许字母、数字和符号
	var regex = /[^a-zA-Z0-9!@#$%^&*(),.?":{}|<>]/g;

	// 如果输入不符合正则表达式，或者长度超过16位，或者长度少于8位，阻止它
	if (regex.test(event.key) || password.length > 16 || (password.length >= 8 && event.key !== undefined)) {
		event.preventDefault();
	}
}